package com.zuma.oci.docker.handler;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.annotation.JSONField;
import lombok.Data;

@Data
public class BuildImageLinePrint {

    public static BuildImageLinePrint build(String content) {
        var data = JSON.parseObject( content, BuildImageLinePrint.class);
        data.setOriginalContent(content);
        return data;
    }

    private String stream;

    private String error;

    private ErrorDetail errorDetail;

    private Aux aux;

    private String status;

    @JSONField(serialize = false, deserialize = false)
    private String originalContent;

    @Override
    public String toString() {
        return originalContent;
    }

    @Data
    public static class ErrorDetail {
        private String code;
        private String message;

        @Override
        public String toString() {
            return StrUtil.format("error -- code:{} -- detail: {}", code, message);
        }
    }

    @Data
    public static class Aux {
        @JSONField(name = "ID")
        private String id;

        @Override
        public String toString() {
            return StrUtil.format("imageId -- {}", id);
        }
    }
}
